package edu.nju.mutest.visitor.collector;

import com.github.javaparser.ast.expr.*;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;

import java.util.List;

/**
 * Collect expressions of basic type, namely expressions that can be resolved(calculated) to byte,
 * short, int, long, float, double, boolean, char. There are six types of numeric expressions:
 * (a) literal, example: 1, 3.4, true
 * (b) variable(NameExpr), example: x, i
 * (c) Unary expression, example: ++x
 * (d) Binary expression, example: 1 + 2, 3 ^ 4
 * (e) Ternary conditional expression, example: x ? 1 : 2
 * (f) Assign expression, example: x = 1
 * (g) method call expression, example: Math.max(1, 2)
 * Note that expression enclosed by () is not considered, because its inner part has been considered.
 */
public class BasicTypeExpressionCollector extends VoidVisitorAdapter<List<Expression>> {

    @Override
    public void visit(BooleanLiteralExpr n, List<Expression> collector) {
        super.visit(n, collector);
        collector.add(n);
    }

    @Override
    public void visit(CharLiteralExpr n, List<Expression> collector) {
        super.visit(n, collector);
        collector.add(n);
    }

    @Override
    public void visit(IntegerLiteralExpr n, List<Expression> collector) {
        super.visit(n, collector);
        collector.add(n);
    }

    @Override
    public void visit(LongLiteralExpr n, List<Expression> collector) {
        super.visit(n, collector);
        collector.add(n);
    }

    @Override
    public void visit(DoubleLiteralExpr n, List<Expression> collector) {
        super.visit(n, collector);
        collector.add(n);
    }

    @Override
    public void visit(NameExpr n, List<Expression> collector) {
        super.visit(n, collector);
        collector.add(n);
    }

    @Override
    public void visit(UnaryExpr n, List<Expression> collector) {
        super.visit(n, collector);
        collector.add(n);
    }

    @Override
    public void visit(BinaryExpr n, List<Expression> collector) {
        super.visit(n, collector);
        collector.add(n);
    }

    @Override
    public void visit(ConditionalExpr n, List<Expression> collector) {
        super.visit(n, collector);
        collector.add(n);
    }

    @Override
    public void visit(AssignExpr n, List<Expression> collector) {
        super.visit(n, collector);
        collector.add(n);
    }

    @Override
    public void visit(MethodCallExpr n, List<Expression> collector) {
        super.visit(n, collector);
        collector.add(n);
    }
}
